import http from './http.js'
export default {
  uploadMed(tempFilePath){
    let url = 'https://hesen-gfn-public.oss-cn-shenzhen.aliyuncs.com'
    return new Promise((resolve, reject) => {
      http.get('/api/aliyunoss/v1/token/mini').then(res => {
        if (res.code === 200) {
          var type = type || 'jpg'
          var type = 'png'
          let date = new Date()
          const random_name = `${date.getFullYear()}/${date.getMonth()+1}/${date.getDate()}/comment/${date.getTime()}.${type}`
          wx.uploadFile({
            url: url, 
            filePath: tempFilePath,
            name: 'file',
            formData: {
              methods: 'post',
              name: tempFilePath,
              key: random_name,
              policy: res.data.policy,
              OSSAccessKeyId: res.data.ossAccessKeyId,
              success_action_status: '200',
              signature: res.data.signature
            },
            success(suc){
              let imgAli = url+'/' + random_name
              resolve(imgAli)
            },
            fail(fail){
              wx.showToast({
                title:fail.errMsg,
                icon: 'none'
              })
              reject(fail)
            }
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: 'none'
          })
        }
      })
    })
  }
}